package com.dycong.common.leetcode.yi;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yilin
 * Date: 2019-07-20
 * Time: 12:35
 */
public class TwoSum {

    public static void main(String[] args) {
        int[] result = twoSum(new int[]{1, 2, 5}, 6);
        System.out.println();
    }

    public static int[] twoSum(int[] numbers, int target) {
        int left = 0;
        int right = numbers.length - 1;
        while (left != right) {
            if (numbers[left] + numbers[right] == target) {
                return new int[]{left + 1, right + 1};
            }
            if (numbers[left] + numbers[right] < target) {
                left++;
                continue;
            }
            if (numbers[left] + numbers[right] > target) {
                right--;
                continue;
            }
        }
        return new int[]{left, right};
    }
}
